<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 14-10-29
 * Time: 下午3:13
 */
header('Content-type=text/html;charset=utf-8');
if(!empty($_GET['submit'])){
    $path = '../1029/';
    if(!file_exists($path));{
        @mkdir("$path",0700);
    }
    $tp = array('image/gif','image/jpg','image/png');
    if(!in_array($_FILES['filename']['type'],$tp)){
        echo '上传文件格式不正确';
        exit();
    }
    //TODO 判断上传文件的类型 以及 大小。
//    echo '<pre>';
//    var_dump($_FILES);
//    echo '</pre>';
    if($_FILES['filename']['name']){
        $files = explode('.',$_FILES['filename']['name']);
        $kz = $files[(count($files)-1)];
        $time = time();
        $name = $time.'.'.$kz;
        $file2 =$path.$name;
        $flag = 1;
    }
    if($flag){
        $result = move_uploaded_file($_FILES['filename']['tmp_name'],$file2);
    }
    if($result){
        echo "<script>alert('上传成功');</script>";
        echo "logo预览:<br /><img src='".$file2."'>";
    }
}else{
    echo "<script>alert('上传文件为空');location='upload.html';</script>";
}